package pl.un4giv3n.mightvsmagic.action.clan;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import pl.un4giv3n.mightvsmagic.entity.Guardian;

public class ShowClanPageAction extends ClanAction{

	private static final long serialVersionUID = 1L;
	private List<Guardian> guardianList;

	@SuppressWarnings("unchecked")
	@Override
	public String execute() {
		EntityManager entityManager = getEntityManager();
		user = getSessionUser(entityManager);
		if (user == null) {
			addActionError("Zaloguj się");
			entityManager.close();
			return LOGIN;
		}
		Query query = entityManager.createNamedQuery("find.all.guardians");
		guardianList = query.getResultList();
		if(user.getClan() == null){
			entityManager.close();
			return INPUT;
		}else{
			clan = user.getClan();
			if(user.isClanAcceptancePending()){
				return "pending";
			}
		}
		entityManager.close();
		return SUCCESS;
	}

	public List<Guardian> getGuardianList() {
		return guardianList;
	}

	public void setGuardianList(List<Guardian> guardianList) {
		this.guardianList = guardianList;
	}
}
